home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / MANDLE_C / GRAPHICS.C next >
Text File  |  1990-05-06  |  1KB  |  74 lines

  1. /*
  2. graphics.c v1.0
  3. Copyright 1990 Josh Pritikin
  4. Tetrahedron Programming
  5. All rights reserved.
  6.  
  7. 2.14.90
  8. */
  9. #define BLANK    0
  10.  
  11. extern WindowPtr    window;
  12. extern EventRecord    event;
  13. extern Boolean        HALT;
  14. static ColorSpec    PriorColors[256];
  15.  
  16. int GETPIXEL(int x, int y)
  17. {
  18.     RGBColor    rgbc;
  19.     
  20.     GetCPixel(x, y, &rgbc);
  21.     return Color2Index(&rgbc);
  22. }
  23.  
  24. PUTPIXEL(int x, int y, int color)
  25. {
  26.     RGBColor    rgbc;
  27.     
  28.     Index2Color((long)color, &rgbc);
  29.     SetCPixel(x, y, &rgbc);
  30.     
  31.     GetNextEvent(everyEvent, &event);
  32.     if (Button()) HALT = true;
  33. }
  34.  
  35. /* (x,y) is the start point and 'dir' the direction to travel in
  36.     'thecount' is the value to fill with
  37.    a line will be drawn until something is run into */
  38. void FillLine(x,y,dir,thecount)
  39. int x,y,dir,thecount;
  40. {
  41.     int            endx=x;
  42.     RGBColor    rgbc;
  43.     
  44.     while (GETPIXEL(endx,y) == BLANK)
  45.         endx -= dir;
  46.     
  47.     Index2Color(thecount, &rgbc);
  48.     RGBForeColor(&rgbc);
  49.     MoveTo(x,y);
  50.     LineTo(endx,y);
  51. }
  52.  
  53. InitScreen()
  54. {
  55.     GDHandle    gdh;
  56.     int            bits_per, i;
  57.     
  58.     gdh = GetMainDevice();
  59.     bits_per = (**(**gdh).gdPMap).pixelSize;
  60.     if ((**(**gdh).gdPMap).cmpSize != bits_per || bits_per != 8) OhShit();
  61.     
  62.     for (i=0; i < 256; i++)
  63.         {
  64.         PriorColors[i].value = i;
  65.         Index2Color((long)i, &PriorColors[i].rgb);
  66.         }
  67. }
  68.  
  69. RestoreScreen()
  70. {
  71.     SetEntries(0, 255, PriorColors);
  72. }
  73.  
  74.